<?php
class Shopconfig extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('shopconfig_model');
	}

	public function index()
	{
		$data['shopconfig'] = $this->shopconfig_model->get_config();
		$data['title'] = 'Shop Config';

		$this->load->view('templates/header', $data);
		$this->load->view('shopconfig/index', $data);
		$this->load->view('templates/footer');
	}

	public function view($id)
	{
		$data['shopconfig'] = $this->shopconfig_model->get_config($id);
		if (empty($data['shopconfig']))
		{
			show_404();
		}
		
		$data['title'] = $data['shopconfig']['key'];

		$this->load->view('templates/header', $data);
		$this->load->view('shopconfig/view', $data);
		$this->load->view('templates/footer');
	}
	
	public function create()
	{
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->library('form_validation');
	
		$data['title'] = 'Create a shop config item';
	
		$this->form_validation->set_rules('key', 'key', 'required');
		$this->form_validation->set_rules('value', 'value', 'required');
	
		if ($this->form_validation->run() === FALSE)
		{
			$this->load->view('templates/header', $data);	
			$this->load->view('shopconfig/create');
			$this->load->view('templates/footer');
		
		}
		else
		{
			$this->shopconfig_model->set_shopconfig();
			//$this->load->view('shopconfig/succes');
			redirect('shopconfig/', 'location', 301);
		}
	}
}
